package com.lingxu.base.system.manage.controller;

import com.lingxu.base.common.api.vo.Result;
import com.lingxu.base.system.manage.entity.SysUserRole;
import com.lingxu.base.system.manage.service.ISysUserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;

@Slf4j
@Api(tags="用户角色信息")
@RestController
@RequestMapping("/system/manage/sysUseerRole")
public class SysUserRoleController {

    @Resource
    private ISysUserRoleService sysUserRoleService;

    

    /**
     * 添加
     *
     * @param sysRole
     * @return
     */
    @ApiOperation(value="角色信息-添加", notes="角色信息-添加")
    @PostMapping(value = "/add")
    public Result<?> add(SysUserRole sysRole) {
        sysUserRoleService.save(sysRole);
        return Result.ok("添加成功！");
    }

    /**
     * 编辑
     *
     * @param sysRole
     * @return
     */
    @ApiOperation(value="角色信息-编辑", notes="角色信息-编辑")
    @PostMapping(value = "/edit")
    public Result<?> edit(SysUserRole sysRole) {
        sysUserRoleService.updateById(sysRole);
        return Result.ok("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id 角色id
     * @return
     */
    @ApiOperation(value="角色信息-通过id删除", notes="角色信息-通过id删除")
    @PostMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name="id")@ApiParam(value = "角色id") String id) {
        sysUserRoleService.removeById(id);
        return Result.ok("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids 一批角色id
     * @return
     */
    @ApiOperation(value="角色信息-批量删除", notes="角色信息-批量删除")
    @PostMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name="ids")@ApiParam(value = "角色id（多个用逗号','隔开）") String ids) {
        if(StringUtils.isNotBlank(ids)){
            this.sysUserRoleService.removeByIds(Arrays.asList(ids.split(",")));
            return Result.ok("批量删除成功！");
        }else{
            return Result.error("未传待删除数据");
        }

    }

}
